<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品信息')" />
    <script src="../../../../../../../ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js"></script>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-manage-add">
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">货品图片：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="productsPicture" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">货品图片：</label>
                <div class="col-sm-8">
                    <input name="productsPicture" id="pic" class="form-control" type="hidden">
                    <a id="url"><img th:src="*{productsPicture}" style="width: 90px;height: 90px"></a>
                    <input type="file" id="abcd">
                </div>
            </div>


            <div class="form-group">    
                <label class="col-sm-3 control-label">货品名称：</label>
                <div class="col-sm-8">
                    <input name="productsName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">货品品牌：</label>
                <div class="col-sm-8">
                    <input name="productsBrand" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">成本价：</label>
                <div class="col-sm-8">
                    <input name="productsCostPrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">销售价：</label>
                <div class="col-sm-8">
                    <input name="productsSalePrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="productsRemark" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
<!--    th:inline="javascript"-->
    <script type="text/javascript" >
        // var prefix = ctx + "products/manage"
        // $("#form-manage-add").validate({
        //     focusCleanup: true
        // });
        //
        // function submitHandler() {
        //     if ($.validate.form()) {
        //         $.operate.save(prefix + "/add", $('#form-manage-add').serialize());
        //     }
        // }

        var prefix = ctx + "products/manage";
        $("#abcd").change(function () {
            var data = new FormData();
            data.append("file", $("#abcd")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        });

        function submitHandler() {
            var formData1 = new FormData(document.getElementById('form-manage-add'));
            $.ajax({
                type:'post',
                url:prefix+'/add',
                //数据不需要编码
                processData : false,
                //数据对象不需要转换成键值对格式
                contentType : false,
                data:formData1,
                success:function(result) {
                    $.operate.successCallback(result);
                }
            })
        }



    </script>
</body>
</html>